import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class ATM extends JFrame {
    private ArrayList<User> list = new ArrayList<>();
    private LoginPanel loginPanel = new LoginPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private CardLayout cardLayout = new CardLayout();
    private OffPanel offPanel = new OffPanel(this);
    private SavePanel savePanel = new SavePanel(this);
    private GetPanel getPanel = new GetPanel(this);
    private FindPanel findPanell = new FindPanel(this);
    private Transfer transferPanell = new Transfer(this);
    private ChangeSecret changeSecretPanell = new ChangeSecret(this);
    private Image bgImg = Util.getImage("/images/background.jpg");

    public FindPanel getFindPanell() {
        return findPanell;
    }

    public void setFindPanell(FindPanel findPanell) {
        this.findPanell = findPanell;
    }

    public ATM() {
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImg, 0, 0, 1024, 768, this);
            }
        });
        this.setLayout(cardLayout);
        this.add("login", loginPanel);
        this.add("menu", menuPanel);
        this.add("off", offPanel);
        this.add("save", savePanel);
        this.add("get", getPanel);
        this.add("find", findPanell);
        this.add("gaimi", changeSecretPanell);
        this.add("zhuan", transferPanell);
        this.setSize(1024, 768);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
        init();
    }

    public void init() {
        list.add(new User("zhangsan", "111111", 10000));
        list.add(new User("lisi", "222222", 20000));
        list.add(new User("wangwu", "333333", 30000));
        list.add(new User("zhaoliu", "444444", 40000));
        list.add(new User("heihei", "555555", 50000));
    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

    public static void main(String[] args) {
        new ATM();
    }

    public ArrayList<User> getList() {
        return list;
    }

    public void setList(ArrayList<User> list) {
        this.list = list;
    }

    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public void setLoginPanel(LoginPanel loginPanel) {
        this.loginPanel = loginPanel;
    }
}
